// pages/my/my.js
import { login, zhuce, property,logout } from '../../utils/http'
Page({
    data: {
        userInfo: null,
        data: [],
        code: null,
        money: [],
        hasMore:true
    },
    onLoad: function (options) {
        var that = this
        wx.login({
            success(res) {
                const { code } = res
                that.setData({ code: code })
                zhuce(that.data.code).then(res => {
                    console.log(res)
                    console.log('用户注册')
                })
            },
        })
    },
    getUserInfo(e) {
        var that = this
        // setTimeout(() => {
            this.setData({ userInfo: e.detail.userInfo })
        // }, 2000);
        wx.login({
            success(res) {
                let code = res.code
                login({ code: code }).then(res => {
                    console.log(res.data)
                    that.setData({ data: res.data })
                    console.log('登陆成功')
                    wx.setStorageSync('token', res.data.token)
                    //资产
                    console.log(that.data.data.token)
                    property(that.data.data.token).then(res => {
                        console.log(res)
                        that.setData({ money: res.data })
                    })
                })
            }
        })
        this.setData({
            hasMore:false
        })
    },
    //退出登录
    logout(){
        let token=wx.getStorageSync('token')
        logout(token).then(res=>{
            console.log(res)
            if(res.msg=='success'){
                this.setData({userInfo:null})
                wx.removeStorageSync('token')
            }
        })
    }
})